import { defineStore } from 'pinia'
import { getHotwordList, getSearchList } from '@/api/search'
export const useSearchStore = defineStore('useSearchStore', {
  state() {
    return {
      // 搜索列表数据
      searchList: [],
      // 热门搜索数据
      hotList: []
    }
  },
  //   请求
  actions: {
    // 搜索列表
    async getSearchListHandler(params: { count: number, limitNum: number, keyword: any }) {
      //发送请求
      const result = await getSearchList(params);

      if ((result as any).code == 200) {
        this.searchList = result.data
      }
    },
    // 热门搜索
    async getHotwordListHandler() {
      //发送请求
      const result = await getHotwordList();
      if ((result as any).code == 200) {
        // 将热门搜索的数据存起来
        this.hotList = result.data

      }
    },
  }
})
